import {
  reqCategory
} from '../../api/index'
Page({

  data: {
    categoryArr: [], //存储分类的数据
    currentIndex: 0,
    goodInfo: {}
  },

  onLoad(options) {
    this.getCategory();
  },

  async getCategory() {
    let result = await reqCategory();
    if (result.code == 200) {
      this.setData({
        categoryArr: result.data,
        goodInfo: result.data[0]
      })
    }
  },
  changeIndex(event) {
    let categoryArr = this.data.categoryArr;
    this.setData({
      currentIndex: event.currentTarget.dataset.index,
      goodInfo:categoryArr[event.currentTarget.dataset.index]
    })
  },
  //商品点击进行详情
  goDetail(event){
     let category2id = event.currentTarget.dataset.id;
     wx.navigateTo({
       url: '/pages/goodDetail/index?category2Id='+category2id,
     })
  }

})